home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 22 / PC Actual CD 22.iso / SHARE / prog / POVRAY / PTD_TREE.ZIP / PTD_TREE.INC next >
Encoding:
Text File  |  1996-09-19  |  14.5 KB  |  420 lines

  1.  
  2. //------------------------------------------------------------------->
  3. //------------------------------------------------------------------->
  4. //
  5. // PTD_Tree.inc - Almost totally random nested loop tree!
  6. //
  7. // Version SEPT-19-96
  8. //
  9. // Created by: Paul T. Dawson
  10. //             ptdawson@voicenet.com
  11. //             http://www.voicenet.com/~ptdawson
  12. //
  13. // <=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>
  14. // <=>-<=>-<=>-<=>                 <=>-<=>-<=>-<=>
  15. // <=>-<=>-<=>-<=>  PUBLIC DOMAIN  <=>-<=>-<=>-<=>
  16. // <=>-<=>-<=>-<=>                 <=>-<=>-<=>-<=>
  17. // <=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>-<=>
  18. //
  19. // Requires POV-Ray 3.0, with the new "rand" function, and loops!
  20. //
  21. // Thank you, POV-Team, for your magnificent program!!!
  22. //
  23. //------------------------------------------------------------------->
  24. //------------------------------------------------------------------->
  25. //
  26. // Note: This file does NOT display the tree. It just makes an object
  27. //       called "Complete_Tree". Then your scene file can show that!
  28. //
  29. // Note: Your main scene file must have all of the usual include files,
  30. //       including "colors.inc" and "textures.inc". If you use any
  31. //       special textures, like "golds" or "stones", you will need to
  32. //       include those files, too (but you-all knew all that!).
  33. //
  34. // Note: Realistic trees use a *LOT* of memory!!!
  35. //
  36. // Note: All of the tree variables MUST be declared in your scene file!
  37. //
  38. //------------------------------------------------------------------->
  39. //------------------------------------------------------------------->
  40. //
  41. // Now, start building the tree!
  42. //
  43. // Don't change anything below here (unless you really want to!).
  44. //
  45. //------------------------------------------------------------------->
  46. //------------------------------------------------------------------->
  47. //
  48. // Don't change these - they are calculated from your variables.
  49.  
  50.         #declare L_Bmin = Large_Branch_Minimum_Angle
  51.         #declare L_Bmax = Large_Branch_Maximum_Angle
  52.                           - Large_Branch_Minimum_Angle
  53.         
  54.         #declare M_Bmin = Medium_Branch_Minimum_Angle
  55.         #declare M_Bmax = Medium_Branch_Maximum_Angle
  56.                           - Medium_Branch_Minimum_Angle
  57.         
  58.         #declare S_Bmin = Small_Branch_Minimum_Angle
  59.         #declare S_Bmax = Small_Branch_Maximum_Angle
  60.                           - Small_Branch_Minimum_Angle
  61.  
  62.         #declare Large_Branch_Size_Range =
  63.         Large_Branch_Size_Max - Large_Branch_Size_Min
  64.  
  65.         #declare Medium_Branch_Size_Range =
  66.         Medium_Branch_Size_Max - Medium_Branch_Size_Min
  67.  
  68.         #declare Small_Branch_Size_Range =
  69.         Small_Branch_Size_Max - Small_Branch_Size_Min
  70.  
  71. //------------------------------------------------------------------->
  72. //------------------------------------------------------------------->
  73. //
  74. // Create one of the leaf styles.
  75. //
  76. // Note: To save memory, the leaves do not get a texture until the
  77. //       very end of the Complete_Tree union. That way, all of the leaves
  78. //       can share one texture. This saves a LOT of memory. You can
  79. //       change this around if you want to, and put the textures up
  80. //       here (memory is cheap, I know, I know!).
  81. //
  82. //------------------------------------------------------------------->
  83. //------------------------------------------------------------------->
  84. //
  85. // Now create the actual REALISTIC (sort-of) leaf.
  86.  
  87.         #if ( Leaf_Type = 0 )
  88.  
  89.         #declare One_Leaf =
  90.  
  91.         union{
  92.  
  93.                 // Leaf part #1
  94.                 sphere{ 0, 3 scale < 0.4, 0.1, 1.0 >
  95.                         translate z * 3
  96.                         rotate x * -30
  97.                         rotate y * 0 }
  98.  
  99.                 // Leaf part #2
  100.                 sphere{ 0, 3 scale < 0.4, 0.1, 1.0 >
  101.                         translate z * 3
  102.                         rotate x * -30
  103.                         rotate y * 120 }
  104.  
  105.                 // Leaf part #3
  106.                 sphere{ 0, 3 scale < 0.4, 0.1, 1.0 >
  107.                         translate z * 3
  108.                         rotate x * -30
  109.                         rotate y * 240 }
  110.  
  111.                 // Scale the entire union. Make the leaf small for
  112.                 // testing branch placement, then make it big!
  113.  
  114.                         scale 0.2
  115.  
  116.         } // End of union.
  117.  
  118.         #end
  119.  
  120. // Now create the actual FAST leaf.
  121.  
  122.         #if ( Leaf_Type = 1 )
  123.  
  124.                 #declare One_Leaf = sphere{ 0, 0.3 }
  125.  
  126.         #end
  127.  
  128. // Now create the actual STRANGE leaf. Change this to anything!
  129.  
  130.         #if ( Leaf_Type = 2 )
  131.  
  132.         #declare One_Leaf = union {
  133.  
  134.                 sphere { 0, 0.3 }
  135.  
  136.                 difference {
  137.  
  138.                         box { < -1, -1, -1 > < 1, 1, 1 > }
  139.  
  140.                         sphere { 0, 1.3 }
  141.  
  142.                 } // End of difference.
  143.  
  144.         } // End of union.
  145.  
  146.         #end
  147.  
  148. // Now create the actual TORUS leaf. This one has a texture!!!
  149.  
  150.         #if ( Leaf_Type = 3 )
  151.  
  152.         #declare One_Leaf = union {
  153.  
  154.                 torus { 1, 0.25 pigment { checker Red, Yellow scale 10 } }
  155.  
  156.                 cylinder { < -1, 0,  0 > < 1, 0, 0 >, 0.1
  157.                 pigment { checker Blue, Cyan scale 0.1 } }
  158.  
  159.                 cylinder { <  0, 0, -1 > < 0, 0, 1 >, 0.1
  160.                 pigment { checker Blue, Cyan scale 0.1 } }
  161.  
  162.         } // End of union.
  163.  
  164.         #end
  165.  
  166. // Create the MESH leaf object - with lots of little triangles!!!
  167.         
  168.         #if ( Leaf_Type = 4 )
  169.  
  170.         #declare One_Leaf = mesh {
  171.  
  172.         #declare A = 1 #while ( A <= TREE_MESH_SIZE )
  173.         
  174.                 // Calculate random location for first point.
  175.                 #declare X1 = ( rand(TREE_RAND) * 2 ) - 1
  176.                 #declare Y1 = ( rand(TREE_RAND) * 2 ) - 1
  177.                 #declare Z1 = ( rand(TREE_RAND) * 2 ) - 1
  178.  
  179.                 // Move a little way from *first* point.
  180.                 #declare X2 = X1 + ( rand(TREE_RAND) * 0.6 ) - 0.3
  181.                 #declare Y2 = Y1 + ( rand(TREE_RAND) * 0.6 ) - 0.3
  182.                 #declare Z2 = Z1 + ( rand(TREE_RAND) * 0.6 ) - 0.3
  183.  
  184.                 // Move a little way from *first* point.
  185.                 #declare X3 = X1 + ( rand(TREE_RAND) * 0.6 ) - 0.3
  186.                 #declare Y3 = Y1 + ( rand(TREE_RAND) * 0.6 ) - 0.3
  187.                 #declare Z3 = Z1 + ( rand(TREE_RAND) * 0.6 ) - 0.3
  188.                 
  189.                 // Make the triangle.
  190.                 triangle { <X1, Y1, Z1>, <X2, Y2, Z2>, <X3, Y3, Z3> }
  191.  
  192.         #declare A = A + 1 #end
  193.  
  194.         } // End of mesh.
  195.  
  196.         #end
  197.  
  198. // Create the ULTRA-MESH leaf object - with lots of little triangles,
  199. // and each "leaf" has a connector "branch" back to <0,0,0>.
  200.         
  201.         #if ( Leaf_Type = 5 )
  202.  
  203.         #declare One_Leaf = mesh {
  204.  
  205.         #declare A = 1 #while ( A <= TREE_MESH_SIZE )
  206.         
  207.                 // Calculate random location for first point.
  208.                 #declare X1 = ( rand(TREE_RAND) * 2 ) - 1
  209.                 #declare Y1 = ( rand(TREE_RAND) * 2 ) - 1
  210.                 #declare Z1 = ( rand(TREE_RAND) * 2 ) - 1
  211.  
  212.                 // Move a little way from *first* point.
  213.                 #declare X2 = X1 + ( rand(TREE_RAND) * 0.6 ) - 0.3
  214.                 #declare Y2 = Y1 + ( rand(TREE_RAND) * 0.6 ) - 0.3
  215.                 #declare Z2 = Z1 + ( rand(TREE_RAND) * 0.6 ) - 0.3
  216.  
  217.                 // Move a little way from *first* point.
  218.                 #declare X3 = X1 + ( rand(TREE_RAND) * 0.6 ) - 0.3
  219.                 #declare Y3 = Y1 + ( rand(TREE_RAND) * 0.6 ) - 0.3
  220.                 #declare Z3 = Z1 + ( rand(TREE_RAND) * 0.6 ) - 0.3
  221.                 
  222.                 // Make the "leaf" triangle.
  223.                 triangle { <X1, Y1, Z1>, <X2, Y2, Z2>, <X3, Y3, Z3> }
  224.                 
  225.                 // Make the "branch" triangles.
  226.                 triangle { <X1, Y1, Z1>, <0, 0, 0>, <0,   0, 0.1> }
  227.                 triangle { <X1, Y1, Z1>, <0, 0, 0>, <0.1, 0, 0  > }
  228.  
  229.         #declare A = A + 1 #end
  230.  
  231.         } // End of mesh.
  232.  
  233.         #end
  234.  
  235. //------------------------------------------------------------------->
  236. //------------------------------------------------------------------->
  237. //
  238. // Now create the tree trunk.
  239.  
  240.         #declare Tree_Trunk = union { 
  241.                 
  242.                 cone { < 0, 0, 0 >, 1.00 < 0, Tree_Trunk_Size, 0 >, 0.80 }
  243.                 sphere { < 0, Tree_Trunk_Size, 0 >, 0.80 }
  244.  
  245.                 texture { Bark_Texture }
  246.                 
  247.                 } // End of union.
  248.  
  249. //------------------------------------------------------------------->
  250. //------------------------------------------------------------------->
  251. //
  252. // Now we begin the CONFUSING nested loops. They create a big union
  253. // called "Complete_Tree". We start with one trunk, and add some large
  254. // branches to it. Then, for each large branch, we add a few medium
  255. // branches - each one is at a random angle. Then, in the inner loop,
  256. // we add small branches. Each one of the small branches gets one leaf
  257. // object attached to it. Whew!
  258. //
  259. // The loops MUST be nested like this - it's the only way to give each
  260. // and every branch a random tilt (relative to the parent branch).
  261. //
  262. // The loops are NOT indented properly, because that put the inner loop
  263. // way off the screen, making things even more confusing!
  264.  
  265.         #declare Complete_Tree =
  266.  
  267.         union {
  268.  
  269.         object { Tree_Trunk }
  270.  
  271.         #declare A = 0 #while ( A < Number_Of_Large_Branches )
  272.  
  273.         union {
  274.  
  275. // Make one large branch.
  276.  
  277.         #declare This_Large_Branch_Size =
  278.                 ( rand(TREE_RAND) * Large_Branch_Size_Range ) +
  279.                 Large_Branch_Size_Min
  280.  
  281.         cone {<0,0,0>,0.60 <0,This_Large_Branch_Size,0>,0.40
  282.                 texture { Bark_Texture } }
  283.                 
  284.         sphere { <0,This_Large_Branch_Size,0>,0.40
  285.                 texture { Bark_Texture } }
  286.  
  287. // Loop to put medium branches on that large branch.
  288.  
  289.         #declare B = 0 #while ( B < Number_Of_Medium_Branches )
  290.  
  291.         union {
  292.  
  293.         #declare This_Medium_Branch_Size =
  294.                 ( rand(TREE_RAND) * Medium_Branch_Size_Range ) +
  295.                 Medium_Branch_Size_Min
  296.  
  297.         cone { <0,0,0>,0.30 <0,This_Medium_Branch_Size,0>,0.20
  298.                 texture { Bark_Texture } }
  299.         
  300.         sphere { <0,This_Medium_Branch_Size,0>,0.20
  301.                 texture { Bark_Texture } }
  302.  
  303. // Loop to put small branches on that medium branch.
  304.  
  305.         #declare C = 0 #while ( C < Number_Of_Small_Branches )
  306.  
  307.         #declare This_Small_Branch_Size =
  308.                 ( rand(TREE_RAND) * Small_Branch_Size_Range ) +
  309.                 Small_Branch_Size_Min
  310.  
  311.         union {
  312.  
  313.         cone { <0,0,0>,0.10 <0,This_Small_Branch_Size,0>,0.05
  314.                 texture { Bark_Texture } }
  315.         
  316.         // (No sphere at the end of that cone - it's invisible!)
  317.  
  318. // The leaf at the end of the small branch.
  319.  
  320.         object { One_Leaf translate y * This_Small_Branch_Size }
  321.  
  322.         // First, spin the vertical branch to a random angle.
  323.         // The branch doesn't really change - this actually
  324.         // just spins the leaf around!
  325.  
  326.                 #declare SpinAngle = (rand(TREE_RAND)*360)
  327.                 rotate y * SpinAngle
  328.  
  329.         // Now, tilt it over a little.
  330.                 #declare BranchAngle = (rand(TREE_RAND)*S_Bmax)+S_Bmin
  331.                 rotate z * BranchAngle
  332.  
  333.         // Rotate it into place, with a little random wiggle.
  334.                 #declare Wiggle=(rand(TREE_RAND)*20)-10
  335.                 #if ( Wiggle_Flag = off ) #declare Wiggle = 0 #end
  336.                 
  337.                 #declare C2 = ( 360 / Number_Of_Small_Branches ) * C
  338.                 rotate y * (C2 + Wiggle)
  339.  
  340.         // Move it up to the top of the Medium_Branch.
  341.         // If flag is "off", then move to the next spot on branch.
  342.  
  343.                 #declare TEMP_HEIGHT = This_Medium_Branch_Size
  344.                 #if ( Branches_On_End_Flag = off )
  345.                         #declare TEMP_HEIGHT = This_Medium_Branch_Size -
  346.                         ((This_Medium_Branch_Size / Number_Of_Small_Branches)*C)
  347.                 #end
  348.  
  349.                 translate y * TEMP_HEIGHT
  350.  
  351.         } // End of object.
  352.  
  353.         #declare C = C + 1 #end
  354.  
  355.         #declare BranchAngle = (rand(TREE_RAND)*M_Bmax)+M_Bmin
  356.         rotate z * BranchAngle
  357.  
  358.         #declare Wiggle=(rand(TREE_RAND)*20)-10
  359.         #if ( Wiggle_Flag = off ) #declare Wiggle = 0 #end
  360.         #declare B2 = ( 360 / Number_Of_Medium_Branches ) * B
  361.         rotate y * ( B2 + Wiggle )
  362.  
  363.         // Move the Medium_Branch up to the top of the Large_Branch.
  364.         // If flag is "off", then move to the next spot on branch.
  365.                 
  366.                 #declare TEMP_HEIGHT = This_Large_Branch_Size
  367.                 #if ( Branches_On_End_Flag = off )
  368.                         #declare TEMP_HEIGHT = This_Large_Branch_Size -
  369.                         ((This_Large_Branch_Size / Number_Of_Medium_Branches)*B)
  370.                 #end
  371.  
  372.                 translate y * TEMP_HEIGHT
  373.                 
  374.         } // End of union.
  375.  
  376.         #declare B = B + 1 #end
  377.  
  378.         #declare BranchAngle = (rand(TREE_RAND)*L_Bmax)+L_Bmin
  379.         rotate z * BranchAngle
  380.  
  381.         #declare Wiggle=(rand(TREE_RAND)*20)-10
  382.         #if ( Wiggle_Flag = off ) #declare Wiggle = 0 #end
  383.         #declare A2 = ( 360 / Number_Of_Large_Branches ) * A
  384.         rotate y * ( A2 + Wiggle )
  385.         
  386.         // Move the Large_Branch up to the top of the Tree_Trunk.
  387.         // If flag is "off", then move to the next spot on trunk.
  388.         // These are spaced differently than the other branches - they
  389.         // start about 3/4 of the way up the trunk.
  390.                 
  391.                 #declare TEMP_HEIGHT = Tree_Trunk_Size
  392.                 #if ( Branches_On_End_Flag = off )
  393.                         #declare TEMP_HEIGHT = Tree_Trunk_Size -
  394.                         ((Tree_Trunk_Size / Number_Of_Large_Branches)*A/4)
  395.                 #end
  396.  
  397.                 translate y * TEMP_HEIGHT
  398.  
  399.         } // End of union.
  400.  
  401.         #declare A = A + 1 #end
  402.  
  403.         // Now, turn all of the leaves green! This doesn't change the
  404.         // branches, because they already have a texture.
  405.  
  406.                 texture { Leaf_Texture }
  407.  
  408.     } // end of Complete_Tree union
  409.  
  410. //------------------------------------------------------------------->
  411. //------------------------------------------------------------------->
  412. //
  413. // Now return to your main file and show "Complete_Tree".
  414. //
  415. //------------------------------------------------------------------->
  416. //------------------------------------------------------------------->
  417. //
  418. // End of this file - bye!
  419.  
  420.